{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "timeAnalysis.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {
        "id": "4gkGgBLNZn7L",
        "colab_type": "code",
        "outputId": "e8ffa8b0-a60e-47b1-e9aa-9b1ed1e2587c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 54
        }
      },
      "source": [
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import pandas as pd\n",
        "import csv\n",
        "import os\n",
        "\n",
        "print(os.listdir(\"./\")) # make sure train.csv is in current directory"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "['.config', 'gpuKDtree1024.csv', 'gpu256.csv', 'gpu64.csv', 'gpuKDtree64.csv', 'cpu.csv', 'gpu512.csv', 'gpuKDtree32.csv', 'gpu128.csv', 'gpuKDtree128.csv', 'gpuKDtree512.csv', 'gpuKDtree256.csv', '.ipynb_checkpoints', 'gpu32.csv', 'gpu1024.csv', 'sample_data']\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "csyUAg_7Z7SH",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "def readCSV(filename):\n",
        "    \"\"\"\n",
        "    takes in a filename\n",
        "    returns a numpy array, with the first row as the\n",
        "        timestamp in seconds, and the second row\n",
        "        as the fps across the last time block\n",
        "    \"\"\"\n",
        "    results = []\n",
        "    with open(filename) as csv_file:\n",
        "        reader = csv.reader(csv_file, delimiter=',')\n",
        "        for line in reader:\n",
        "            step = float(line[0])\n",
        "            timestamp = float(line[1])\n",
        "            fps = float(line[2])\n",
        "            results.append([timestamp, fps])\n",
        "\n",
        "    return np.array(results).T"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wSNb2OlwuB3Y",
        "colab_type": "code",
        "outputId": "70000171-52ab-4a33-bce4-68b19f8fd185",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 238
        }
      },
      "source": [
        "directory='./'\n",
        "kd = []\n",
        "naive = []\n",
        "cpu = []\n",
        "for filename in os.listdir(directory):\n",
        "    if filename.endswith(\".csv\"): \n",
        "        data = readCSV(filename)\n",
        "        t = data[0,:-1]\n",
        "        t1 = data[0,1:]\n",
        "        dt = t1-t\n",
        "        avg = np.average(dt)\n",
        "        if 'KDtree' in filename:\n",
        "            print(int(filename[-8:-4]),' KDtree average iteration time: ', avg)\n",
        "            kd.append( ( int(filename[-8:-4]),avg ) )\n",
        "        elif 'KDtree' not in filename and 'gpu' in filename:\n",
        "            l = 11-len(filename)\n",
        "            print(int(filename[-8:-4]),' naive average iteration time: ', avg)\n",
        "            naive.append( ( int(filename[-8:-4]),avg ) )\n",
        "        else:\n",
        "            print('cpu average iteration time: ', avg)\n",
        "            cpu.append(avg)\n",
        "\n",
        "kd = np.array(kd).T\n",
        "naive = np.array(naive).T\n",
        "cpu = np.array(cpu)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "1024  KDtree average iteration time:  0.0025833333333333333\n",
            "32  naive average iteration time:  0.02819047619047619\n",
            "128  KDtree average iteration time:  0.00225\n",
            "64  KDtree average iteration time:  0.002166666666666667\n",
            "cpu average iteration time:  4.548441717791411\n",
            "256  KDtree average iteration time:  0.0022083333333333334\n",
            "512  naive average iteration time:  0.022666666666666665\n",
            "32  KDtree average iteration time:  0.0020833333333333333\n",
            "512  KDtree average iteration time:  0.0022083333333333334\n",
            "128  naive average iteration time:  0.022857142857142857\n",
            "256  naive average iteration time:  0.024904761904761905\n",
            "64  naive average iteration time:  0.025380952380952386\n",
            "1024  naive average iteration time:  0.02523809523809524\n"
          ],
          "name": "stdout"
        }
      ]
    }
  ]
}